# FLEXINVERT task catalogue aggregator

PROJECT_CATALOG_DIR ?= $(MAKEFILE_DIR)
FLEX_REF_PATHS := /home/linden/Downloads/FLEXINVERT/docs/roadmaps/roadmaps $(PROJECT_ROOT) $(PROJECT_ROOT)/prompt $(PROJECT_CATALOG_DIR)
FLEX_SUCCESS_DIR := logs/flexinvert/success

FLEX_BRANCHES := baseline optimized
FLEX_BRANCH_SUFFIX_baseline := BASE
FLEX_BRANCH_SUFFIX_optimized := OPT
FLEX_BRANCH_TAG_baseline := flex-baseline
FLEX_BRANCH_TAG_optimized := flex-optimized
FLEX_BRANCH_SUCCESS_DIR_baseline ?= $(FLEX_SUCCESS_DIR)/baseline/success
FLEX_BRANCH_SUCCESS_DIR_optimized ?= $(FLEX_SUCCESS_DIR)/optimized/success

define FLEX_FIND_REF
$(strip $(firstword $(foreach dir,$(FLEX_REF_PATHS),$(if $(wildcard $(dir)/$(1)),$(dir)/$(1)))))
endef

FLEX_REF = $(strip $(if $(call FLEX_FIND_REF,$(1)),$(call FLEX_FIND_REF,$(1)),$(error FLEXINVERT reference not found: $(1) (searched $(FLEX_REF_PATHS)))))

define FLEX_REGISTER_BRANCH_TASK
$(eval _flex_branch := $(strip $(2)))
$(eval _flex_suffix := $(FLEX_BRANCH_SUFFIX_$(_flex_branch)))
$(eval _flex_task_id := $(strip $(1))_$(_flex_suffix))
$(eval _flex_tags := $(strip $(11) $(FLEX_BRANCH_TAG_$(_flex_branch))))
$(call REGISTER_TASK,$(_flex_task_id),$(3),$(4),$(5),$(6),$(7))
$(call REGISTER_META,$(_flex_task_id),$(8),$(9),$(10),$(_flex_tags),$(12),$(13))
$(call REGISTER_SUCCESS,$(_flex_task_id),$(if $(strip $(14)),$(14),$(FLEX_BRANCH_SUCCESS_DIR_$(_flex_branch))/$(_flex_task_id).md))
$(eval BRANCH_OF_$(_flex_task_id) := $(_flex_branch))
endef

define FLEX_REGISTER_DEP_PAIR
$(foreach branch,$(FLEX_BRANCHES),$(call REGISTER_DEP,$(1)_$(FLEX_BRANCH_SUFFIX_$(branch)),$(2)_$(FLEX_BRANCH_SUFFIX_$(branch))))
endef

# Stream task registrations
include $(PROJECT_CATALOG_DIR)includes/streams/foundation.mk
include $(PROJECT_CATALOG_DIR)includes/streams/parity.mk
include $(PROJECT_CATALOG_DIR)includes/streams/solver.mk
include $(PROJECT_CATALOG_DIR)includes/streams/scaling.mk
include $(PROJECT_CATALOG_DIR)includes/streams/validation.mk
include $(PROJECT_CATALOG_DIR)includes/streams/docs.mk
include $(PROJECT_CATALOG_DIR)includes/streams/experiments.mk

# Task dependencies
$(call FLEX_REGISTER_DEP_PAIR,FLEX_P52,FLEX_P51)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_P53,FLEX_P52)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_P54,FLEX_P53)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_B2,FLEX_P51)
$(call REGISTER_DEP,FLEX_B2_BASE_PREP,FLEX_P51_BASE)
$(call REGISTER_DEP,FLEX_B2_BASE_QA,FLEX_B2_BASE_PREP)
$(call REGISTER_DEP,FLEX_B2_BASE_SCALING,FLEX_B2_BASE_QA)
$(call REGISTER_DEP,FLEX_B2_BASE_INITCONC,FLEX_B2_BASE_PREP)
$(call REGISTER_DEP,FLEX_B2_BASE_QA_HARDEN,FLEX_B2_BASE_QA)
$(call REGISTER_DEP,FLEX_B2_BASE,FLEX_B2_BASE_PREP)
$(call REGISTER_DEP,FLEX_B2_BASE,FLEX_B2_BASE_QA)
$(call REGISTER_DEP,FLEX_B2_BASE,FLEX_B2_BASE_SCALING)
$(call REGISTER_DEP,FLEX_B2_BASE,FLEX_B2_BASE_INITCONC)
$(call REGISTER_DEP,FLEX_B2_BASE,FLEX_B2_BASE_QA_HARDEN)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_B3,FLEX_B2)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_B4,FLEX_B3)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_C1,FLEX_P51)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_C2,FLEX_C1)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_C3,FLEX_C2)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_C4,FLEX_C3)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_C5,FLEX_C4)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_C6,FLEX_C5)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_TEST1,FLEX_C5)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_DOC1,FLEX_C5)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_DOC2,FLEX_C6)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_EXP1,FLEX_C6)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_EXP2,FLEX_P54)
$(call FLEX_REGISTER_DEP_PAIR,FLEX_REPO1,FLEX_C6)
